﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using CFZS.IDAL;
using CFZS.DALFactory;

namespace CFZS.BLL
{
    /// <summary>
    /// BasePerson
    /// </summary>
    public partial class BasePerson
    {
        private readonly IBasePerson dal = DataAccess.CreateBasePerson();
        public BasePerson()
        { }
        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(long Id)
        {
            return dal.Exists(Id);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public long Add(CFZS.Model.BasePerson model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(CFZS.Model.BasePerson model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(long Id)
        {

            return dal.Delete(Id);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string Idlist)
        {
            return dal.DeleteList(Idlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public CFZS.Model.BasePerson GetModel(long Id)
        {

            return dal.GetModel(Id);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中
        /// </summary>
        //public CFZS.Model.BasePerson GetModelByCache(long Id)
        //{

        //    string CacheKey = "BasePersonModel-" + Id;
        //    object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
        //    if (objModel == null)
        //    {
        //        try
        //        {
        //            objModel = dal.GetModel(Id);
        //            if (objModel != null)
        //            {
        //                int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
        //                Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
        //            }
        //        }
        //        catch { }
        //    }
        //    return (CFZS.Model.BasePerson)objModel;
        //}

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<CFZS.Model.BasePerson> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<CFZS.Model.BasePerson> DataTableToList(DataTable dt)
        {
            List<CFZS.Model.BasePerson> modelList = new List<CFZS.Model.BasePerson>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                CFZS.Model.BasePerson model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new CFZS.Model.BasePerson();
                    if (dt.Rows[n]["Id"] != null && dt.Rows[n]["Id"].ToString() != "")
                    {
                        model.Id = long.Parse(dt.Rows[n]["Id"].ToString());
                    }
                    if (dt.Rows[n]["GuidPerson"] != null && dt.Rows[n]["GuidPerson"].ToString() != "")
                    {
                        model.GuidPerson = dt.Rows[n]["GuidPerson"].ToString();
                    }
                    if (dt.Rows[n]["Name"] != null && dt.Rows[n]["Name"].ToString() != "")
                    {
                        model.Name = dt.Rows[n]["Name"].ToString();
                    }
                    if (dt.Rows[n]["Birthday"] != null && dt.Rows[n]["Birthday"].ToString() != "")
                    {
                        model.Birthday = DateTime.Parse(dt.Rows[n]["Birthday"].ToString());
                    }
                    if (dt.Rows[n]["Sex"] != null && dt.Rows[n]["Sex"].ToString() != "")
                    {
                        model.Sex = dt.Rows[n]["Sex"].ToString();
                    }
                    if (dt.Rows[n]["BaseOrgSysCode"] != null && dt.Rows[n]["BaseOrgSysCode"].ToString() != "")
                    {
                        model.BaseOrgSysCode = long.Parse(dt.Rows[n]["BaseOrgSysCode"].ToString());
                    }
                    if (dt.Rows[n]["BaseTitle"] != null && dt.Rows[n]["BaseTitle"].ToString() != "")
                    {
                        model.BaseTitle = dt.Rows[n]["BaseTitle"].ToString();
                    }
                    if (dt.Rows[n]["BasePosition"] != null && dt.Rows[n]["BasePosition"].ToString() != "")
                    {
                        model.BasePosition = dt.Rows[n]["BasePosition"].ToString();
                    }
                    if (dt.Rows[n]["Phone"] != null && dt.Rows[n]["Phone"].ToString() != "")
                    {
                        model.Phone = dt.Rows[n]["Phone"].ToString();
                    }
                    if (dt.Rows[n]["Mobile"] != null && dt.Rows[n]["Mobile"].ToString() != "")
                    {
                        model.Mobile = dt.Rows[n]["Mobile"].ToString();
                    }
                    if (dt.Rows[n]["Email"] != null && dt.Rows[n]["Email"].ToString() != "")
                    {
                        model.Email = dt.Rows[n]["Email"].ToString();
                    }
                    if (dt.Rows[n]["Descr"] != null && dt.Rows[n]["Descr"].ToString() != "")
                    {
                        model.Descr = dt.Rows[n]["Descr"].ToString();
                    }
                    if (dt.Rows[n]["IsActive"] != null && dt.Rows[n]["IsActive"].ToString() != "")
                    {
                        model.IsActive = int.Parse(dt.Rows[n]["IsActive"].ToString());
                    }
                    if (dt.Rows[n]["LineNo"] != null && dt.Rows[n]["LineNo"].ToString() != "")
                    {
                        model.LineNo = long.Parse(dt.Rows[n]["LineNo"].ToString());
                    }
                    if (dt.Rows[n]["Createdat"] != null && dt.Rows[n]["Createdat"].ToString() != "")
                    {
                        model.Createdat = DateTime.Parse(dt.Rows[n]["Createdat"].ToString());
                    }
                    if (dt.Rows[n]["CreatedBy"] != null && dt.Rows[n]["CreatedBy"].ToString() != "")
                    {
                        model.CreatedBy = dt.Rows[n]["CreatedBy"].ToString();
                    }
                    if (dt.Rows[n]["CreatedByName"] != null && dt.Rows[n]["CreatedByName"].ToString() != "")
                    {
                        model.CreatedByName = dt.Rows[n]["CreatedByName"].ToString();
                    }
                    if (dt.Rows[n]["UpdatedAt"] != null && dt.Rows[n]["UpdatedAt"].ToString() != "")
                    {
                        model.UpdatedAt = DateTime.Parse(dt.Rows[n]["UpdatedAt"].ToString());
                    }
                    if (dt.Rows[n]["UpdatedBy"] != null && dt.Rows[n]["UpdatedBy"].ToString() != "")
                    {
                        model.UpdatedBy = dt.Rows[n]["UpdatedBy"].ToString();
                    }
                    if (dt.Rows[n]["UpdatedByName"] != null && dt.Rows[n]["UpdatedByName"].ToString() != "")
                    {
                        model.UpdatedByName = dt.Rows[n]["UpdatedByName"].ToString();
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            return dal.GetRecordCount(strWhere);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  Method
    }
}
